
import {mapState,mapActions} from 'vuex'
export default {
	data() {
		return {
			
		}
	},
	filters:{
		 formatPriceName(v){
			let map={
				'yellow':'黄水晶',
				'purple':'紫水晶',
				'blue':'蓝水晶',
				'yellow_log':'黄水晶',
				'purple_log':'紫水晶',
				'blue_log':'蓝水晶',
			}
			return map[v]
		}
	},
	computed:{
		exchangeStatus(){  //兑换商品状态  0:敬请期待，1未开始，2：已开始，3已结束，4已兑完,5水晶不足
			if(this.info.id&&this.info.status){
					
				let timeStatus = this.$tools.checkTimeBetween(this.nowTimestamp, this.startTime, this.endTime);
				if(timeStatus==2||this.stock<=0){
					return 4;
				}
				
				
				
				if(this.balance<this.info.crystal_number){  //余额不足，一个都买不起
					return 5
				}
				
				// //库存没了或者一个都买不了
				// if(!this.maxCount) return 4;
				
				//未开始
				if(!timeStatus) return 1;
			
				//可以买了
				return 2;
			}
			return 0;
		},
		startTime(){//开始兑换时间
			if(this.info.id){
				return this.info.release_time*1000
			}
			return new Date().getTime()
		},
		endTime(){//结束兑换时间
			if(this.info.id){
				return this.info.stop_sale_time*1000
			}
			return new Date().getTime()
		},
		stock(){//库存
			if(this.info.id){
				return this.info.stock
			}
			return 0
		},
		maxCount(){//最大兑换数量
			if(this.info.id){
				return Math.min(Math.floor(this.balance/this.info.crystal_number),this.info.purchase_limit);
			}
		},
		balance(){//水晶余额
			if(this.info.id){
				let {crystal_type}=this.info;
				return this.userInfo['crystal_'+crystal_type]
			}
			return 0;
		},
		 countDown(){
			 if(this.exchangeStatus==1){
				return this.startTime-this.nowTimestamp; 
			 }
			 return 0;
		 },
		 ...mapState('config',['nowTimestamp']),
	},
	created(){
		this.getUserInfo();
	},
	methods:{
		...mapActions('user',['getUserInfo']),
		...mapActions('config',['createNowTimeTimer']),
		crystalIcon(type) {
			let obj = {
				'yellow':'hsj',
				'purple':'zsj',
				'blue':'lsj',
				'yellow_log':'hsj',
				'purple_log':'zsj',
				'blue_log':'lsj',
			}
			return obj[type]
		}
	}
}